#ifndef _GLWINDOW_H
#define _GLWINDOW_H

#include "includes.h"
#include <QtOpenGL/QGLWidget>
#include <QtGui/QMouseEvent>
#include "rendermanager.h"
#include "toolinvoker.h"
#include "View.h"
#include "ViewEditor.h"
#include "ViewGame.h"
#include <string>
#include "Drawing.h"
#include "ProceduralTerrainTool.h"
#include "globalstates.h"

//TEST FILES
#include "brushtoolatd.h"
#include "selectiontoolatd.h"
#include "testdriver.h"

class GLWindow : public QGLWidget
{

    Q_OBJECT
public:
    QTimer *q;
    friend class EditorInterface;
    RenderManager* getRenderManager();
    GlobalStates* global;
    GLWindow(QWidget *parent = NULL);
    void setCurrentView(View*);
    View* getCurrentView();
    static GLWindow* getInstance();
protected:
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
    void drawOverlay();
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void keyReleaseEvent(QKeyEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void timerEvent(QTimerEvent *event);
    void leaveEvent(QEvent *event);
    void enterEvent(QEvent *event);
    void wheelEvent(QWheelEvent * event);
    void setSelectedTool(Tool*);

private:
    View* currentView;
    TestDriver* tester;
    //float tx,ty,tz;
    //int roty,rotx;
    RenderManager* rend;

    ToolInvoker *mainTool;

    bool button_down;
    void init_material();
    void init_light();

signals:
    void updateStatus(const QString &);
};

inline
void GLWindow::setCurrentView(View* view){
    if(currentView)currentView->destroy();
    currentView = view;
    currentView->init();
    currentView->resize(width(),height());
}

inline
View* GLWindow::getCurrentView(){
    return currentView;
}


#endif // GLWINDOW_H
